package leetcode.greed;

//nums = [2,3,1,1,4]
// [3,2,1,0,4]
public class Test55 {

    public static void main(String[] args) {
        int[] nums = {3,2,1,0,4};
        boolean b = canJump(nums);
        System.out.println(b);
    }

    public static boolean canJump(int[] nums) {
        int prev = 0,index = 1;
        if (nums.length == 1){
            return true;
        }
        while (index< nums.length){
            if (nums[prev] == 0){
                break;
            }
            if (nums[prev] - nums[index] <= index - prev){
                prev = index;
            }
                index++;
        }
        if (nums[prev] +prev >= nums.length-1){
            return true;
        }
        return false;
    }
}
